#ifndef OMNIWIDGET_H
#define OMNIWIDGET_H

#include <QWidget>
#include <QtCore>
#include <QDebug>
#include <stdio.h>
#include <string.h>
#include <HD/hd.h>
#include <HDU/hduError.h>
#include <HDU/hduVector.h>

using namespace std;

/** \brief Stores the haptic device state */
struct DeviceDisplayState
{
    HDdouble pos[3]; // device position
    HDdouble force[3]; // force to be exerted by the device
    HDint nCurrentButtons, nLastButtons;
    HHD dHandle;  // haptic device handle
    double planeStiffness; // Virtual place stiffness

    /** Y co-ordinate of virtual plane */
    double planeY;

    double penetrationDistance;  //
    double mm3aSpringStiffness; // virtual spring stiffness
    hduVector3Df mm3aSpringLength; // virtual spring length
    HDdouble anchor[3]; // spring anchor point
    bool renderForce; // flag to render force or not
    int currentDACValues[3]; // gets the dac values sent to the motor amp.

};

HDCallbackCode HDCALLBACK DeviceStateCallback(void *pUserData);

/** \brief Phantom Omni widget. Implements virtual environment on the Omni

  The Omni is contrained to horizontal plane when the experiment is started. To command the end-effector the top button on the Omni pen has to be pressed. A virtual spring is implemented from the point at which the button is pressed giving a sense of how much velocity input is given to the manipulator
  */

class OmniWidget : public QThread
{
    Q_OBJECT

public:
    OmniWidget(QObject *parent=0);
    // ~OmniWidget();

    int countRun;

    /** Haptic device handle */
    HHD hHD;
    /** stores the current state of the device (position, force) */
    DeviceDisplayState *state;

    bool omniConnected;

    void open();
    void close();
    void init();

public slots:
    void run();

};


#endif // OMNIWIDGET_H
